#![allow(unused_imports,dead_code,unused_assignments)]
use axum::{
    extract::{Form, Query, Json, Multipart,DefaultBodyLimit},
    routing::{get,post},
    response::Response,
    body::{Body, Bytes},
    Router
};
use crate::{controller::goods_type_controller::find_goods_type_by_id, domain::GoodsTypeBean, serviceimpl::recommend_service::find_recommend_by_id};
use crate::domain::GoodsTypeQueryRequest;
use crate::serviceimpl::goods_type_service::list_active_goods_types as service_list_active_goods_types;
use serde::{Deserialize};
use serde_json::{Value,Map};
use std::fs;
use tower_http::{trace::TraceLayer};

#[derive(Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct IdsRequest {
	pub ids: String,
}

pub fn goods_type_cust_controller() -> Router {
	Router::new()
	.route("/listActiveGoodsTypes", post(list_active_goods_types))
}

pub async fn list_active_goods_types() ->String {
	let goods_types = service_list_active_goods_types().await;
	match goods_types {
		Err(_) => {
			println!("Error!");
			r#"{  "rows": null,  "success": true}"#.to_string()
		},
		Ok(goods_types) => {
			let json = serde_json::to_string_pretty(&goods_types).unwrap();
			//println!("{}", json);

			let mut map = Map::new();
			map.insert("success".to_string(), Value::from(true));
			map.insert(
				"rows".to_string(),
				serde_json::from_str(&json).unwrap(),
			);

			let resultjson = serde_json::to_string_pretty(&map).unwrap();
			//println!("{}", resultjson);
			return resultjson;
		}
	}
}
